package drive.Controller;

import drive.Model.Comment;
import drive.Service.ServiceInterface.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
//初步测试完成，2025.3.18
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    // 查询所有评论
    @GetMapping()
    public String selectAllComments() {
        return commentService.findAll();
    }

    // 根据commentID查询评论
    @GetMapping("/{commentID}")
    public String selectCommentByCommentID(@PathVariable("commentID") int commentID) {
        return commentService.findByCommentID(commentID);
    }

    // 根据articleID查询评论
    @GetMapping("/article/{articleID}")
    public String selectCommentsByArticleID(@PathVariable("articleID") int articleID) {
        return commentService.findByArticleID(articleID);
    }

    // 根据userID查询评论
    @GetMapping("/user/{userID}")
    public String selectCommentsByUserID(@PathVariable("userID") int userID) {
        return commentService.findByUserID(userID);
    }

    // 根据parentCommentID查询评论
    @GetMapping("/parent/{parentCommentID}")
    public String selectCommentsByParentCommentID(@PathVariable("parentCommentID") int parentCommentID) {
        return commentService.findByParentCommentID(parentCommentID);
    }

    // 新增评论
    @PostMapping()
    public String addComment(@RequestBody Comment comment) {
        return commentService.add(comment);
    }

    // 更新评论
    @PutMapping()
    public String updateComment(@RequestBody Comment comment) {
        return commentService.update(comment);
    }

    // 删除评论
    @DeleteMapping("/{commentID}")
    public String deleteComment(@PathVariable("commentID") int commentID) {
        return commentService.delete(commentID);
    }
}